package gamble.money.command;

import gamble.money.dao.MoneyDoaImpl;
import gamble.money.vo.MoneyVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class WithdrawalController {
	private MoneyDoaImpl dao;
	
	public void setDao(MoneyDoaImpl dao) {
		this.dao = dao;
	}
	
	//출금 페이지
	@RequestMapping("/withdrawalmoney.do")
	public ModelAndView withdrawalmoney(HttpServletRequest request){
		
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		int totalMoney =dao.getMoney(id);
		
		ModelAndView mv = new ModelAndView();
		mv.addObject("totalMoney",totalMoney);
		mv.setViewName("money/withdrawalmoney");
		return mv;
	}
	
	
	@RequestMapping("/withdrawalpro.do")
	public ModelAndView withdrawalPro(HttpServletRequest request,MoneyVo vo){
		
		//비지니스로직 Start
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		vo.setId(id);
		vo.setClassify(0);//구분값 0이면 출금
//		System.out.println("출금해야하는 값" + vo.getInMoney());
		
		
		String result = dao.goWithdrawal(vo);//출금
		System.out.println("출금 결과 : "+result);
		
		//비지니스로직 End
		
		ModelAndView mv = new ModelAndView();
		mv.addObject("result","");
		mv.setViewName("redirect:/chargelist.do");
		return mv;
	}
}
